package top.pmwly;
/**
 * @author Herther
 * @version 1.0.0
 * @ClassName linearSearch.java
 * @Description 线性查找算法
 * @createTime 2021年08月08日 16:34:00
 */
public class LinearSearch {

    private LinearSearch(){}

    public static void main(String[] args) {
        //Integer[] arr =  {12,92,26,25,87,16,83,54,23,27,35};
        //Integer target = select(35,arr);
        //Student[] students = {
        //        new Student("LiLi"),
        //        new Student("Mini"),
        //        new Student("Herther"),
        //        new Student("XiaoMin")
        //};
        //int target1 = select(new Student("herther"), students);
        //System.out.println(target1);
        //性能测试
        int n = 10000000;
        //生成数组
        Integer[] data = ArrayGenerate.arrayGenerate(n);
        //记录开始时间
        long startTime = System.nanoTime();
        for (int k=0;k<100;k++){
            select(n,data);
        }
        //结束时间
        long endTime = System.nanoTime();
        //转换成秒
        double time = (endTime - startTime) /1000000000.0;
        System.out.println("run :"+ n+ ",time："+time +" s");
    }

    public static <T> int select(T target,T[] arr){
        for (int i = 0; i < arr.length ;i++) {
             if (arr[i].equals(target)){
                 return i;
             }
        }
        return -1;
    }
}


